package com.kevis.zhunblog.admin.handler;

import com.alibaba.fastjson.JSON;
import com.kevis.webCommon.tools.web.ServletUtil;
import com.kevis.webCommon.web.domain.response.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * SecureLogoutSuccessHandler
 *
 * @Author kevis
 * @Date 2023/3/28 11:38
 */
@Component
public class SecureLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        SecurityContextHolder.clearContext();
        Result result =Result.success(200,"注销成功");
        ServletUtil.write(JSON.toJSONString(result));
    }
}
